package com.alex.common.tools;

public class Pair<F, S> {

	public final F fst;

	public final S snd;

	public Pair(F obj, S obj1) {
		fst = obj;
		snd = obj1;
	}

	public String toString() {
		return (new StringBuilder()).append("Pair[").append(fst).append(",")
				.append(snd).append("]").toString();
	}

	private static boolean equals(Object obj, Object obj1) {
		return obj == null && obj1 == null || obj != null && obj.equals(obj1);
	}

	@SuppressWarnings("unchecked")
	public boolean equals(Object obj) {
		return (obj instanceof Pair) && equals(fst, ((Pair<F, S>) obj).fst)
				&& equals(snd, ((Pair<F, S>) obj).snd);
	}

	public int hashCode() {
		if (fst == null)
			return snd != null ? snd.hashCode() + 1 : 0;
		if (snd == null)
			return fst.hashCode() + 2;
		else
			return fst.hashCode() * 17 + snd.hashCode();
	}

}
